import { ADD_PERSON } from '../actions/person';

const initialState = {
    persons: [{
        id: '001',
        name: 'John',
        age: 25,
    },
    {
        id: '002',
        name: 'Jane',
        age: 30,
    },
    {
        id: '003',
        name: 'Bob',
        age: 40,
    },
    {
        id: '004',
        name: 'Alice',
        age: 35,
    }],
};

export default function personReducer(state = initialState, action) {
    const { type, data } = action;
    if (type === ADD_PERSON) {
        return { persons: [data, ...state.persons] }
    } else {
        return state;
    }
}